cmake_minimum_required(VERSION 2.8)

INCLUDE_DIRECTORIES(${THRIFT_INCLUDE_DIR})
INCLUDE_DIRECTORIES(/usr/include)
INCLUDE_DIRECTORIES(${CLOG_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${MUDUO_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${ZOOKEEPER_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${THRIFT_GEN_CPP_PATH})
INCLUDE_DIRECTORIES(${AGENT_SRC_PATH})
INCLUDE_DIRECTORIES(${CTHRIFT_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${UTIL_PATH})
INCLUDE_DIRECTORIES(${RULE_PATH})
INCLUDE_DIRECTORIES(${MAFKA_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${MONITOR_COLLECTOR_PATH})
INCLUDE_DIRECTORIES(${LOG4CPLUS_PATH})
INCLUDE_DIRECTORIES(${LOG4CPLUS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${COMMON_PATH})
INCLUDE_DIRECTORIES(${MNS_PATH})
INCLUDE_DIRECTORIES(../../thrid_party/log4cplus)
INCLUDE_DIRECTORIES(../mns)
INCLUDE_DIRECTORIES(../util)
INCLUDE_DIRECTORIES(../comm)
INCLUDE_DIRECTORIES(../../common/gen-cpp)
INCLUDE_DIRECTORIES(../remote/monitor)
INCLUDE_DIRECTORIES(../rule)

add_definitions(-Wall)

IF (ENABLE_COVERAGE)
    SET(CMAKE_CXX_FLAGS "-g -Wall -O0 -fPIC -DMUDUO_STD_STRING -DHAVE_NETINET_IN_H -DGTEST")
ELSE ()
    SET(CMAKE_CXX_FLAGS "-g -Wall -O2 -fPIC -DMUDUO_STD_STRING -DHAVE_NETINET_IN_H -DGTEST")
ENDIF ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -DUSE_CLOG_SUPPORT")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
MESSAGE(STATUS "CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}")
IF (ENABLE_COVERAGE)
   include(CodeCoverage)
   APPEND_COVERAGE_COMPILER_FLAGS()
ENDIF ()
MESSAGE(STATUS "CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
option(CHRION_DOWNLOAD_GTEST "Download and build a fresh copy of googletest. Requires Internet access." ON)
set(CHRION_SYSTEM_GTEST_SOURCE_DIR "" CACHE PATH "System googletest source directory.")
if (CHRION_DOWNLOAD_GTEST)
   include(SetupGtest)
	elseif (CHRION_SYSTEM_GTEST_SOURCE_DIR)
		add_subdirectory("${CHRION_SYSTEM_GTEST_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/system-googletest-build")
else ()
   message(FATAL_ERROR "Googletest is not available")
endif ()

SET(THRIFT_GEN_CPP_PATH ../../common/gen-cpp)
MESSAGE(STATUS "THRIFT_GEN_CPP_PATH DIR ${THRIFT_GEN_CPP_PATH}")

SET(THRIFT_GENCPP_SRCS
		${THRIFT_GEN_CPP_PATH}/MNSCacheService.cpp
		${THRIFT_GEN_CPP_PATH}/mnsc_data_constants.cpp
		${THRIFT_GEN_CPP_PATH}/mnsc_data_types.cpp
		${THRIFT_GEN_CPP_PATH}/mnsc_service_constants.cpp
		${THRIFT_GEN_CPP_PATH}/mnsc_service_types.cpp
		${THRIFT_GEN_CPP_PATH}/naming_common_constants.cpp
		${THRIFT_GEN_CPP_PATH}/naming_common_types.cpp
		${THRIFT_GEN_CPP_PATH}/naming_service_constants.cpp
		${THRIFT_GEN_CPP_PATH}/naming_service_types.cpp
		${THRIFT_GEN_CPP_PATH}/unified_protocol_constants.cpp
		${THRIFT_GEN_CPP_PATH}/unified_protocol_types.cpp
		${THRIFT_GEN_CPP_PATH}/ServiceAgent.cpp
		)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}  -fprofile-arcs -ftest-coverage-lgcov")

AUX_SOURCE_DIRECTORY(. TEST_SRCS)
AUX_SOURCE_DIRECTORY(../src/comm AGENT_COMM_SRCS)
AUX_SOURCE_DIRECTORY(../src/util AGENT_UTILS_SRCS)
AUX_SOURCE_DIRECTORY(../src/rule AGENT_RULE_SRCS)
AUX_SOURCE_DIRECTORY(../src/mns AGENT_MNS_SRCS)
AUX_SOURCE_DIRECTORY(../remote/monitor MONITOR_COLLECTOR_SRCS)
AUX_SOURCE_DIRECTORY(../../thrid_party/logs/log4cplus AGENT_LOG4CPLUS_SRCS)
INCLUDE_DIRECTORIES(SYSTEM ${GTEST_INCLUDE_DIR})


ADD_EXECUTABLE(agent_unittest ${TEST_SRCS} ${AGENT_MNS_SRCS} ${AGENT_MCC_SRCS}
		${AGENT_FALCON_SRCS} ${AGENT_COMMONLOG_SRCS} ${AGENT_LOG4CPLUS_SRCS}
		${MUDUO_BASE_LIBRARY}
        ${THRIFT_GENCPP_SRCS} ${AGENT_COMM_SRCS} ${AGENT_UTILS_SRCS}
		${AGENT_RULE_SRCS} ${AGENT_MAFKA_SRCS} ${MONITOR_COLLECTOR_SRCS}
        )

TARGET_LINK_LIBRARIES(agent_unittest -Xlinker "-("
        ${THRIFT_STATIC_LIB} ${CTHRIFT_LIBRARY} ${LOG4CPLUS_LIBRARY}
				${MUDUO_NET_LIBRARY} ${MUDUO_HTTP_LIBRARY}
		${ZOOKEEPER_LIBRARY} ${THRIFTNB_STATIC_LIB}
         boost_system event uuid ssl dl
		 gtest pthread rt -Xlinker "-)" -Wl
        )


